package util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jakarta.servlet.http.HttpServletRequest;

import java.io.BufferedReader;
import java.io.IOException;
import java.net.http.HttpRequest;
import java.util.Objects;

public class GetJsonUtil {

    public static Object get(HttpServletRequest req, Object o) throws IOException {
        // 使用BufferedReader读取请求体中的JSON字符串
        BufferedReader reader = req.getReader();
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
        String jsonStr = sb.toString();

        Object object= JSONObject.parseObject(jsonStr,o.getClass());
        return object;
    }

}
